package day6.Component;

import java.awt.BorderLayout;
import java.awt.CardLayout;
import java.awt.Color;

import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.JTable;

public class TestCardLayout extends JFrame {

	public TestCardLayout(String title) {
		this.setTitle(title);
		this.setSize(400, 500);
		this.setLocationRelativeTo(null);
		this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		
		initComponent();
		
		// 放到最后显示窗口
		this.setVisible(true);
	}
	// 初始化
	private void initComponent() {
		//total Panel
		JPanel totalPanel= new JPanel(); 
		
		//cardlayout
		totalPanel.setLayout(new CardLayout());
		//默认只会使用第一张卡片
		//现有两张卡片   卡片在容器里
		
		//可以通过卡片布局管理器 切换卡片
		JPanel p1 = new JPanel();
		p1.setBackground(Color.blue);
		JPanel p2 = new JPanel();
		p2.setBackground(Color.white);
		totalPanel.add("蓝色",p1);
		totalPanel.add("白色",p2);
		CardLayout card = (CardLayout)totalPanel.getLayout();
		card.show(totalPanel, "白色");
		this.add(totalPanel);
		
		
		
	}

	public static void main(String[] args) {
		new TestCardLayout("卡片布局");
	}

}
